﻿using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities.Auditing;

namespace Leo.Awesome.DictionaryManagement.Domain
{
    public class Section : FullAuditedEntity<Guid>
    {
        public Section()
        {
            Items = new List<Section>();
        }
        public Section(
            Guid id,
            Guid? parentId,
            string name,
            string code,
            string treePath,
            int orderIndex,
            bool isSystem,
            string domain = "defalut",
            bool isSection = true)
        {
            Id = id;
            ParentId = parentId;
            Name = name;
            Code = code;
            TreePath = treePath;
            OrderIndex = orderIndex;
            IsSystem = isSystem;
            Domain = domain;
            Items = new List<Section>() { };
            IsSection = isSection;
        }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        
        /// <summary>
        /// 是否是节点
        /// </summary>
        public bool IsSection { get; set; }=true;

        /// <summary>
        /// 编号
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 路径
        /// </summary>
        public string TreePath { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int OrderIndex { get; set; }

        /// <summary>
        /// 父节点
        /// </summary>
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 域
        /// </summary>
        public string Domain { get; set; }

        /// <summary>
        /// 是否为系统字段
        /// </summary>
        public bool IsSystem { get; set; }
        
        /// <summary>
        /// 集合
        /// </summary>
        public virtual List<Section> Items { get; }

        /// <summary>
        /// 子项
        /// </summary>
        /// <param name="sectionItem"></param>
        /// <returns></returns>
        public Section AddChindRenItem([NotNull] Section sectionItem)
        {
            Items.Add(sectionItem);
            return this;
        }
    }
}
